///////////////////////////////////////////////////////////////////////////////////
// File:        License.h
// Purpose:     Declarations of the License class wich stores the license data and
//              contains the encode/decode algorithms
// Author:      Tukero
// Copyright:   (c) Tukero <tukero@gmail.com>
// Licence:     GNU/LGPL v3
///////////////////////////////////////////////////////////////////////////////////

#ifndef _TNOD_License_
#define _TNOD_License_

#ifndef WX_PRECOMP
#  include <wx/wx.h>
#else
#  include <wx/wxprec.h>
#endif

#include <wx/regex.h>
#include <wx/config.h>
#include <wx/tokenzr.h>

#include <wx/listimpl.cpp>

class License
{
private:
    wxString        m_Username;
    wxString        m_Password;
    unsigned long   m_ExpirationDate;
    int             m_ExpirationState;
    bool            m_IsValid;

    enum OPERATIONS
    {
        ENCODE,
        DECODE        
    };
    enum FORMATS
    {
        BINARY,
        STRING
    };

    static void   workPass(FORMATS formatInput, FORMATS formatOutput, OPERATIONS operation, wxString* strInput, wxMemoryBuffer* binInput, wxString *strOutput, wxMemoryBuffer* binOutPut);
    static        wxChar GetPassCharW(int position);
public:
    License();
    License(License *);
    bool IsValid();
    void SetValid(bool validity);
    bool IsSameAs(const License &anotherLicense);
      
    License(const wxString username, const wxString password, bool isValid = false, int state = 0);
    void SetUsername(wxString );
    wxString GetUsername();
    
    void SetPassword(wxString );
    wxString GetPassword();

    void SetExpirationDate(unsigned long ms);
    unsigned long GetExpirationDate();

    void SetExpirationState(int state);
    int GetExpirationState();


    static void EncodePass(wxString strPass, wxString &binStrPass);
    static void EncodePass(wxString strPass, wxMemoryBuffer &binPass);
    static wxString DecodePass(wxString binStrPass);
    static wxString Encode2Validate(const wxString username, const wxString password);
};
WX_DECLARE_LIST(License, LinkListLicense);
#endif